package ca.swank.hardquor;

import java.util.Comparator;

/**
* A toolkit that may be useful for implementing board logic.
*
* @author Jesse Wilson
* @version 1.0 10/18/2001
*/
public class hardquorBoardTools
{
  private static coordinateComparator coordCompare = new coordinateComparator();

  public static int[] getSquareInDirection(int[] source, int direction)
  { if(direction == hardquorBoard.DIR_ABOVE)
      return new int[] { source[0], source[1] + 1 };
    else if(direction == hardquorBoard.DIR_RIGHT)
      return new int[] { source[0] + 1, source[1] };
    else if(direction == hardquorBoard.DIR_BELOW)
      return new int[] { source[0], source[1] - 1 };
    else if(direction == hardquorBoard.DIR_LEFT)
      return new int[] { source[0] - 1, source[1] };
    else return null;
  }

  public static boolean coordsEqual(int[] a, int[] b)
  { return (coordCompare.compare(a,b) == 0);
  }

  public static Comparator getCoordinateComparator()
  { return coordCompare;
  }

}

class coordinateComparator implements Comparator
{ public coordinateComparator()
  {
  }

  public int compare(Object o1, Object o2)
  { int[] a = (int[])o1;
    int[] b = (int[])o2;
    if(a[0] == b[0])
    { if(a[1] == b[1]) return 0;
      else return a[1] - b[1];
    } else
    { return a[0] - b[0];
    }
  }
}